package com.example.repair_service.mapper;


import com.example.repair_service.entity.UserAddressEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {

    /**
     * 条件查询
     * @param addressBook
     * @return
     */
    List<UserAddressEntity> list(UserAddressEntity addressBook);

    /**
     * 新增
     * @param address
     */
    @Insert("INSERT INTO user_address " +
            "(user_id, contact_name, contact_phone, province, city, district, detail_address, is_default) " +
            "VALUES (#{userId}, #{contactName}, #{contactPhone}, #{province}, #{city}, #{district}, #{detailAddress}, #{isDefault})")
    void insert(UserAddressEntity address);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from user_address where id = #{id}")
    UserAddressEntity getById(Long id);

    /**
     * 根据id修改
     * @param addressBook
     */
    void update(UserAddressEntity addressBook);

    /**
     * 根据 用户id修改 是否默认地址
     * @param addressBook
     */
    @Update("update user_address set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(UserAddressEntity addressBook);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from user_address where id = #{id}")
    void deleteById(Long id);

}
